package com.uduemc.biso.master.backend.request;

import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import com.uduemc.biso.core.extities.center.MasterUser;
import com.uduemc.biso.master.backend.validator.MasterUserUsernameCreate;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Accessors(chain = true)
public class MastermanageAppend {

	@NotBlank(message = "登陆用户名不能为空")
	@Pattern(regexp = "\\w+", message = "登陆用户名只能是字母、数字、下划线组成")
	@Length(min = 4, max = 64, message = "登陆用户名的长度只能为4～64个字符")
	@MasterUserUsernameCreate
	public String username;

	@NotBlank(message = "登陆密码不能为空！")
	@Length(min = 4, max = 32, message = "登陆密码的长度只能为4～32个字符")
	public String passwordHash;

	@NotBlank(message = "用户昵称不能为空")
	@Length(max = 32, message = "用户昵称不能超过32个字符")
	public String name;

	@Range(min = 0, max = 1, message = "登录到用户站点、无效只能为 0、1 两个值")
	public short loginNode;

	@Length(max = 32, message = "联系电话不能超过32个字符")
	public String phone;

	@Length(max = 32, message = "Email 不能超过32个字符")
	public String email;

	public MasterUser makeMasterUser() {
		MasterUser masterUser = new MasterUser();
		masterUser.setName(this.getName());
		masterUser.setUsername(this.getUsername());
		masterUser.setPhone(this.getPhone());
		masterUser.setEmail(this.getEmail());
		masterUser.setLoginNode(this.getLoginNode());
		return masterUser;
	}
}
